|
|
|
|
|
|
|
the Visual Basic main menu. Enter SQLMain(cRunFile) as the name, select the Sub radio button, and select the Public radio button. Now enter the code in Listing A.11. |
|
|
|
|
|
|
|
|
Listing A.11. Coding the SQLMain routine. |
|
|
|
|
|
|
|
|
Sub SQLMain(Optional cRunFile As Variant)
'
' main loop for interpreting SQL ASCII file
'
If IsMissing(cRunFile) = True Then
cRunFile = ""
End If
'
InitApp ' clean up environment
SQLFileOpen CStr(cRunFile) ' open the script
If intGlobalErr = False Then
SQLFileProcess ' process the script
End If
SQLFileClose ' close the script
'
cRunFile = "" ' clear passed parm
'If intGlobalErr = False Then
' MsgBox "Script Completed", vbInformation
'End If
End Sub |
|
|
|
|
|
|
|
|
The routine in Listing A.11 does all the things mentioned earlier and adds two more actions. You perform some application initialization. You set an error condition during the SQLFileOpen routine in case something goes wrong when you open the file. Then you can check that error condition before you try to run the SQLFileProcess routine. Also, once the script processing is complete, you show the user a friendly little message box. |
|
|
|
|
|
|
|
|
Let's start building the next level of routines. The first is the SQLFileOpen routine. Use the CommonDialog control to get the filename from the user. If a filename was selected, open that file for processing, and then return to SQLMain. Notice that you have built in an error trap to catch any problems that may occur during file selection and opening. |
|
|
|
|
|
|
|
|
Select Tools | Add Procedure from the Visual Basic main menu and set the name to SQLFileOpen(cSQLFile). Make this a Public Sub procedure. Now enter the code in Listing A.12 in the procedure window. |
|
|
|
|
|